package OPeration;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOPeration
        implements IOPeration {//删除图书
    @Override
    public void work(BookList bookList) {
        System.out.println("Del~~");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的图书:");
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())) {
                for(int j = i;j<currentSize-1;j++) {
                    Book book1 = bookList.getBook(j+1);
                    bookList.setBooks(book1,j);
                }
                bookList.setUsedSize(currentSize-1);
                System.out.println("删除成功...");
                return;
            }
        }
        System.out.println("没找到你要删除的图书...");
    }
}
